#include "OpenGLRenderData.h"
POCELAIN_NAMESPACE_BEGIN
OpenGLMaterialRenderData::OpenGLMaterialRenderData()
{
}
OpenGLMaterialRenderData::~OpenGLMaterialRenderData()
{
    //Clear uniform
    clearUniforms();
    //Clear program
    setProgram(nullptr);
}
void OpenGLMaterialRenderData::setProgram(OpenGLShaderProgram *val)
{
    if(mProgram!=nullptr)
    {
        mProgram->release();
    }
    mProgram = val;
    if(mProgram!=nullptr)
    {
        mProgram->retain();
    }
}

void OpenGLMaterialRenderData::addUniform(GLint location, IUniform *uniform)
{
    if(uniform==nullptr)
        return;
    auto it = mMapLocationUniform.find(location);
    uniform->retain();
    if(it!=mMapLocationUniform.end())
    {
        it->second->release();
        it->second = uniform;
    }
    else
    {
        mMapLocationUniform.insert(std::make_pair(location,uniform));
    }
}

void OpenGLMaterialRenderData::clearUniforms()
{
    for(auto &it : mMapLocationUniform)
    {
        it.second->release();
    }
    mMapLocationUniform.clear();
}

OpenGLGeometryRenderData::OpenGLGeometryRenderData()
{
}
OpenGLGeometryRenderData::~OpenGLGeometryRenderData()
{
}
POCELAIN_NAMESPACE_END
